// const utils = {};

String.prototype.format = function (args) {
  var result = this;
  if (arguments.length < 1) {
    return result;
  }

  var data = arguments; //如果模板参数是数组
  if (arguments.length == 1 && typeof args === 'object') {
    //如果模板参数是对象
    data = args;
  }
  for (var key in data) {
    var value = data[key];
    if (undefined != value) {
      result = result.replace('{' + key + '}', value);
    }
  }
  return result;
};

export function NumToPx(num) {
  return `${num}px`;
}

export function isTextEmpty(text) {
  if (text == undefined || text == null || text.trim() == '') {
    return true;
  }

  return false;
}

export function IsNullObject(ob) {
  if (ob == undefined || ob == null) {
    return true;
  }
  return false;
}

export function Delay(delayTime) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, delayTime);
    return;
  });
}

//超过万
export function TenThousandToStr(num) {
  return num > 9999 ? (num / 10000).toFixed(1) + '万' : num;
}

//当前时间戳
export function TimeStamp() {
  return Date.parse(new Date());
}
export function TimestampToTime(timestamp) {
  var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var Y = date.getFullYear() + '-';
  var M =
    (date.getMonth() + 1 < 10
      ? '0' + (date.getMonth() + 1)
      : date.getMonth() + 1) + '-';
  var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  // var h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
  // var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
  // var s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
  return Y + M + D;
}
